|
|
|
|
|
|
|
Of course using the error numbers themselves is not a very good practice. You should probably declare global constants to define each error that you may encounter. |
|
|
|
|
|
|
|
|
If the user is getting a divide-by-zero error, you can easily remedy this via some simple coding on your part. All you have to do is detect that a divide-by-zero error has occurred by checking the Err.Number property to see if its number 11. If it is, you can inform the user of the problem and prompt the user for a new divisor using the InputBox() function. Heres how: |
|
|
|
 |
|
|
|
|
Private Sub cmdFixResume_Click()
On Error GoTo Error_EH
txtResult = CInt(txtDividend) / CInt(txtDivisor)
Exit Sub
Error_EH:
If Err.Number = 11 Then MsgBox "A Divide By Zero Error Has Occurred, " & _
"Please enter a new divisor"
txtDivisor = InputBox("Enter a Divisor", "Divisor")
Resume Else
MsgBox Err.Description
End If
Err.Clear
Exit Sub
End Sub |
|
|
|
|
|
|
|
|
After the user inputs the new divisor, you can then perform a Resume statement to retry the operation one more time. |
|
|
|
|
|
|
|
|
Lets take a look at what happens when error handling is only used in some but not all procedures in a program. When clicked, the CallStack command button on the FileLen.frm form in the sample project calls three procedures. The first procedure |
|
|
|
|
|